
<template src="./tpl.html"></template>

<script>
import { CONSENT_GET_XDSLS_SQDSJ, CONSENT_GET_CURRENT_VERSION } from "_SERVICES/api";
import { trimAll } from "UTILS/string";
import { isvalidateNum2 } from "UTILS/validate";
import { timeFormatter, getDay } from "UTILS/format";
import { getStorage, setStorage } from "UTILS/util";


// 心电生理室
import page from "@/modules/CST/mxins/page";
export default {
  name: "xdsls_list",
  mixins: [page],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      formInline: {
        KDSJ: [getDay(-15, 1), timeFormatter(new Date(), 2)],
        ZYH: "",
        BRBH: "",
        BRXM: "",
        TJBH: ""
      },
      card_obj: {},

      headers: [
        {
          label: "ID",
          prop: "REPORTSNO",
        },
        {
          label: "就诊卡号",
          prop: "BRBH",
        },
        {
          label: "住院号",
          prop: "ZYH",
        },
        {
          label: "体检编号",
          prop: "TJBH",
        },
        {
          label: "患者姓名",
          prop: "BRXM",
        },
        {
          label: "性别",
          prop: "BRXB_STR",
          width: 60
        },
        {
          label: "联系方式",
          prop: "LXDH",
        },
        {
          label: "诊疗类型",
          prop: "ZLLX_STR",
        },
        {
          label: "检查项目",
          prop: "JCXM",
        },
        {
          label: "开单科室",
          prop: "SJKS",
        },
        {
          label: "开单时间",
          prop: "KDSJ_STR",
        },
        {
          label: "状态",
          prop: "ZTBZ_STR",
        },
      ],
    };
  },
  created() {
    if (this.$route.query && this.$route.query.BRBH) {
      this.formInline.BRBH = this.$route.query.BRBH
    } 
    this.getList();

  },
  beforeDestroy() {
    // setStorage({
    //   name: "xdsls_list_params",
    //   value: JSON.stringify(this.formInline),
    // });
  },

  mounted() { },
  methods: {
    resetForm(name) {

      this.formInline = {
        KDSJ: [getDay(-15, 1), timeFormatter(new Date(), 2)],
        ZYH: "",
        BRBH: "",
        BRXM: "",
        TJBH: ""
      },
      // this.$refs[name].resetFields();
      this.$refs.ybCard.clear();
      this.card_obj = {}
      // this.search();
    },

    //不带刷卡数据
    search_2() {
      this.$refs.ybCard.clear();
      this.card_obj = {}
      this.search()
    },

    getList() {

      this.listLoading = true;
      let params = {
        ...this.formInline,
        BSLX: this.card_obj.BSLX || "",//BSLX
        WYBS: this.card_obj.WYBS || "",//WYBS
      };

      if (params.WYBS) {
        params = {
          KDSJ: params.KDSJ,
          BSLX: params.BSLX,
          WYBS: params.WYBS,
          insuplc_admdvs:this.card_obj.insuplc_admdvs
        }
      }


      Object.assign(params, this.getParams());

      return CONSENT_GET_XDSLS_SQDSJ(params)
        .then((res) => {
          this.listLoading = false;
          this.listQuery.totalNum = res.data.totalNum;
          this.tableData = res.data.list;

          this.setBrbh(res.data.patientInfo)

          this.CONSENT_GET_CURRENT_VERSION();//检查版本
        })
        .catch((res) => {
          this.listLoading = false;
          this.downloadLoading = false;
      });
    },
   
    //刷卡只受预约时间的约束
    back(obj) {
      if (obj.code == 0) {
        this.card_obj = obj;
        this.search();
      } else {
        this.card_obj = {}
        if (obj.msg) {
          this.$message.error(obj.msg)
        }
      }

    },
    rowClick(row) {
      console.log(row)
      let baseUrl =  `http://localhost:9527/CST.html#/consentList?`;
      if(process.env.VUE_APP_build_type == 'production') {
        baseUrl =  `http://10.1.6.124:99/CST.html#/consentList?`;

      }
      baseUrl+=`fromPage=PATIENT_LIST&BRBH=${row.BRBH}&BRXM=${row.BRXM}&GET_PATIENT_BY_PRIMARY=${row.REPORTSNO}&GET_PATIENT_TYPE=XDSLS_SQD`

      window.open(baseUrl, '_blank');

      // this.$router.push({
      //   path: "/consentList",
      //   query: {
      //     fromPage: "PATIENT_LIST",
      //     BRBH: row.BRBH,
      //     BRXM: row.BRXM,
      //     GET_PATIENT_BY_PRIMARY: row.REPORTSNO,
      //     GET_PATIENT_TYPE: "NJ_SQD",
      //   }

      // })
    }
  },
};
</script>

<style lang="less"></style>
